package com.cmiov.pulsar.pulsardemo;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.core.env.Environment;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

import static springfox.documentation.builders.RequestHandlerSelectors.withClassAnnotation;

/**
 * @Author: joe
 * @Date: 17-8-11 上午11:52.
 * @Description:
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

//    public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.cmiov.andfleethe.microservice.api";
    public static final String VERSION = "1.0.0";

    @Autowired
    private Environment environment;

    // Swagger Config.
    @Bean
    @ConditionalOnMissingBean(Docket.class)
    public Docket customImplementation() {

        ParameterBuilder parameterBuilder = new ParameterBuilder();
        List<Parameter> parameters = new ArrayList<>();


        return new Docket(DocumentationType.SWAGGER_2)
                .select()
//                .apis(basePackage(SWAGGER_SCAN_BASE_PACKAGE))
                .apis(withClassAnnotation(Api.class))
                .build()
                .apiInfo(metaData()).globalOperationParameters(parameters);
    }

    private ApiInfo metaData() {
        return new ApiInfoBuilder()
                .title("CARDAY后端服务API说明文档")
                .description("The document has integrated CARDAY's APIs of MicroServices by each module.")
                .license("Apache 2.0")
                .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
                .termsOfServiceUrl("")
                .version(VERSION)
                .contact(new Contact("Sen Li", "http://wiki.virtueit.net/display/CMDT/CARDAY+Backend+vService+API+Spec", "sen.li@cm-dt.com"))
                .build();
    }

}
